package com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.RootImageInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.entity.SearchRootImageInfo;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.service.ICacheImageService;
import com.sxfq.loansupermarket.backsystem.modular.qualityAssurance.service.IDentalImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 质量管理控制器
 *
 * @author
 * @Date
 */
@Controller
@RequestMapping("/cacheImage")
public class CacheImageController extends BaseController {
    @Autowired
    ICacheImageService cacheService;

    @Autowired
    private SqlMapper sqlMapper;

    /**
     * 缓存影像列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(SearchRootImageInfo info, HttpServletRequest request) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            if("1".equals(info.getCacheImage())){
                List<RootImageInfo> list = cacheService.selectOrthodonticsByCache(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cacheService.selectOrthodonticsByCache(page, info);
                }
                page.setTotal(cacheService.getOrthodonticsCacheCount(page, info));
                page.setRecords(list);
            }
            if("2".equals(info.getCacheImage())){
                List<RootImageInfo> list = cacheService.selectCanalByCache(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cacheService.selectCanalByCache(page, info);
                }
                page.setTotal(cacheService.getCanalCacheCount(page, info));
                page.setRecords(list);
            }
            if("3".equals(info.getCacheImage())){
                List<RootImageInfo> list = cacheService.selectScalingByCache(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cacheService.selectScalingByCache(page, info);
                }
                page.setTotal(cacheService.getScalingCacheCount(page, info));
                page.setRecords(list);
            }
            if("4".equals(info.getCacheImage())){
                List<RootImageInfo> list = cacheService.selectPeriodontalByCache(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cacheService.selectPeriodontalByCache(page, info);
                }
                page.setTotal(cacheService.getPeriodontalCacheCount(page, info));
                page.setRecords(list);
            }
            if("5".equals(info.getCacheImage())){
                List<RootImageInfo> list = cacheService.selectPlantByCache(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cacheService.selectPlantByCache(page, info);
                }
                page.setTotal(cacheService.getPlantCacheCount(page, info));
                page.setRecords(list);
            }
            if("6".equals(info.getCacheImage())){
                List<RootImageInfo> list = cacheService.selectRepairByCache(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = cacheService.selectRepairByCache(page, info);
                }
                page.setTotal(cacheService.getRepairCacheCount(page, info));
                page.setRecords(list);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }
}
